package com.shangbang.verb.controller.record;

import com.shangbang.verb.core.BaseResponse;
import com.shangbang.verb.service.record.StoryService;
import io.swagger.annotations.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Api(value = "录音--故事操作类类接口", tags = "录音--故事操作类类", description = "故事集的上传、列表等")

@RestController
@RequestMapping(value = "/record/story")
public class StoryController {

    @Autowired
    private StoryService storyService;

    /**
     * 创建我的故事集
     * @param request
     * @param response
     * @param title
     * @param duration
     * @param music_url
     * @param images
     * @param uid
     * @return
     */
    @ApiOperation(value = "我的故事集上传接口",notes = "我的故事集上传接口")
    @ApiResponses({ @ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = -1, message = "操作失败") })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "title", value = "名称", required = true, dataType = "String"),
            @ApiImplicitParam(name = "duration", value = "描述", required = true, dataType = "String"),
            @ApiImplicitParam(name = "music_url", value = "音频地址", required = true, dataType = "int"),
            @ApiImplicitParam(name = "images", value = "图片地址，xxxx,xxxxx,xxxxx", required = true, dataType = "String"),
            @ApiImplicitParam(name = "uid", value = "用户id", required = true, dataType = "int"),
    })
    @RequestMapping(value = "/createStory", method = {RequestMethod.POST, RequestMethod.GET})
    public BaseResponse createStory(HttpServletRequest request, HttpServletResponse response,
                                               @RequestParam(required = true) String title,
                                               @RequestParam(required=true) String duration,
                                               @RequestParam(required=true) String music_url,
                                               @RequestParam(required = true) String images,
                                               @RequestParam(required = true) Integer uid
                                                                                            ) {
            Object result = "";
            Integer code = 0;
            String msg = "成功";
            storyService.createStory(title,duration,music_url,images,uid);

            return new BaseResponse(code, msg, result);
    }

    /**
     * 获取故事集详情接口
     * @param request
     * @param response
     * @param story_id
     * @return
     */
    @ApiOperation(value = "获取故事集详情接口",notes = "获取故事集详情接口")
    @ApiResponses({ @ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = -1, message = "操作失败") })
    @ApiImplicitParams({
                @ApiImplicitParam(name = "story_id", value = "故事集id", required = true, dataType = "int"),
    })
    @RequestMapping(value = "/getStoryInfo", method = {RequestMethod.POST, RequestMethod.GET})
    public BaseResponse getStoryInfo(HttpServletRequest request, HttpServletResponse response,
                                    @RequestParam(required = true) Integer story_id
    ) {
        Object result = "";
        Integer code = 0;
        String msg = "成功";
        result =  storyService.getStoryInfo(story_id);

        return new BaseResponse(code, msg, result);
    }

    /**
     * 获取故事集列表接口
     * @param request
     * @param response
     * @return
     */
    @ApiOperation(value = "获取故事集列表接口",notes = "获取故事集列表接口，返回值state，1是喜欢2是未喜欢")
    @ApiResponses({ @ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = -1, message = "操作失败") })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid", value = "用户id", required = false, dataType = "int"),
            @ApiImplicitParam(name = "page", value = "第几页", required = true, dataType = "int"),
            @ApiImplicitParam(name = "num", value = "当前页数", required = true, dataType = "int"),
            @ApiImplicitParam(name = "type", value = "0为所有,1为自己的", required = true, dataType = "int"),

    })
    @RequestMapping(value = "/getStoryList", method = {RequestMethod.POST, RequestMethod.GET})
    public BaseResponse getStoryList(HttpServletRequest request, HttpServletResponse response,
                                     @RequestParam(required = false) Integer uid,
                                     @RequestParam(required = true) Integer page,
                                     @RequestParam(required = true) Integer num,
                                     @RequestParam(required = true) Integer type

    ) {
        Object result = "";
        Integer code = 0;
        String msg = "成功";
        result =  storyService.getStoryList(uid,(page-1)*num,num,type);

        return new BaseResponse(code, msg, result);
    }

}
